package com.example.meterialproject.view_models

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.TypedArray
import android.database.Cursor
import android.net.Uri
import android.provider.ContactsContract
import androidx.lifecycle.ViewModel
import com.example.meterialproject.R
import com.example.meterialproject.bean.ChipBean
import com.pchmn.materialchips.model.ChipInterface
import kotlin.math.sin

/**
 *
 * @ClassName: ChipEditViewModel
 * @Author: android 超级兵
 * @CreateDate: 1/11/22$ 11:11 AM$
 * TODO
 */
class ChipEditViewModel : ViewModel() {


    /*
     * 作者:android 超级兵
     * 创建时间: 1/11/22 11:14 AM
     * TODO 获取自定义信息
     */
    @SuppressLint("Range")
    fun getDataList(context: Context) = let {
        val imageList: TypedArray = context.resources.obtainTypedArray(R.array.image_list)
        val nameList = context.resources.getStringArray(R.array.emoji_name_list)

        // 找出最小值并循环
        val list = (0 until Math.min(imageList.length(), nameList.size)).map {
            ChipBean(it, null,
                imageList.getDrawable(it),
                nameList[it],
                "没网络,随便填")
        }.toList()

        // 释放资源
        imageList.recycle()
        list
    }
}